package com.music.checkpoints.common.core.page;


import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import java.io.Serializable;
import java.util.List;

@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Page<T> implements Serializable {

    /**
     * 数据列表
     */
    private List<T> data;

    /**
     * 当前页码
     */
    private Integer pageNo;


    /**
     * 分页大小
     */
    private Integer pageSize;

    /**
     * 总计录数
     */
    private Long dataTotal;


    /**
     * 构造方法
     *
     * @param data      数据列表
     * @param pageNo    当前页码
     * @param pageSize  页大小
     * @param dataTotal 总计录数
     */
    public Page(Integer pageNo, Long dataTotal, Integer pageSize, List<T> data) {
        this.data = data;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.dataTotal = dataTotal;
    }

    public Page() {
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Long getDataTotal() {
        return dataTotal;
    }

    public void setDataTotal(Long dataTotal) {
        this.dataTotal = dataTotal;
    }

    @Override
    public String toString() {
        return "Page{" +
                "data=" + data +
                ", pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", dataTotal=" + dataTotal +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Page<?> page = (Page<?>) o;

        if (data != null ? !data.equals(page.data) : page.data != null) {
            return false;
        }
        if (pageNo != null ? !pageNo.equals(page.pageNo) : page.pageNo != null) {
            return false;
        }
        if (pageSize != null ? !pageSize.equals(page.pageSize) : page.pageSize != null) {
            return false;
        }
        return dataTotal != null ? dataTotal.equals(page.dataTotal) : page.dataTotal == null;
    }

    @Override
    public int hashCode() {
        int result = data != null ? data.hashCode() : 0;
        result = 31 * result + (pageNo != null ? pageNo.hashCode() : 0);
        result = 31 * result + (pageSize != null ? pageSize.hashCode() : 0);
        result = 31 * result + (dataTotal != null ? dataTotal.hashCode() : 0);
        return result;
    }
}